﻿using Liju.Common;
using Liju.Model;
using LiJu.Db;
using LiJu.Model.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace LiJu.Record
{
    public partial class TaskRecord : UserControl
    {
        /// <summary>
        /// 记录表格默认字体
        /// </summary>
        private Font defaultFont = new Font("Microsoft YaHei", 9);
        /// <summary>
        /// 所有产品数据
        /// </summary>
        List<ProductTaskRecord> ProductTaskRecord = new List<ProductTaskRecord>();

        /// <summary>
        /// 产品名称数据
        /// </summary>
        List<string> ProudctNameData = new List<string>();

        /// <summary>
        /// 产品条码数据
        /// </summary>
        List<string> BarcodeData = new List<string>();

        /// <summary>
        /// 参数列表
        /// </summary>
        Dictionary<string, bool> columnParams = new Dictionary<string, bool>();

        /// <summary>
        /// 表格标题列表
        /// </summary>
        Dictionary<string, string> columnHeaderText = new Dictionary<string, string>();

        /// <summary>
        /// 螺丝型号
        /// </summary>
        private List<ScrewModel> screwModels = new List<ScrewModel>();
        /// <summary>
        /// 任务参数
        /// </summary>
        //private List<ScrewDriverParamModel> screwdriverParams = new List<ScrewDriverParamModel>();
        //mod by zhu
        private List<DDKScrewParam> screwdriverParams = new List<DDKScrewParam>();

        /// <summary>
        /// 套筒型号
        /// </summary>
        private List<SleeveModel> sleeveModels = new List<SleeveModel>();

        /// <summary>
        /// 任务状态类型
        /// 0未执行 1 Pass 2 NG 3执行中 4品质PASS 5品质NG 6品质重做
        /// </summary>
        Dictionary<int, string> TaskStatus = new Dictionary<int, string>()
        {
            {0,"未执行" },
            {1,"Pass" },
            {2,"NG" },
            {3,"执行中" },
            {4,"品质PASS" },
            {5,"品质NG" },
            {6,"品质重做" }
        };
        public TaskRecord()
        {
            InitializeComponent();
            historyRecordButton.HistoryRecordAction += ChangeHistoryRecord;
            settingColumnCombox.SelectItemEvent += SelectColumnParamEvent;
            gdview_RecordList.CellMouseEnter += gdview_RecordList_CellMouseEnter;
            gdview_RecordList.CellMouseLeave += gdview_RecordList_CellMouseLeave;
            gdview_RecordList.CellFormatting += Gdview_RecordList_CellFormatting;
            gdview_RecordList.CellClick += Gdview_RecordList_CellClick;
            ResetData();
        }

        private void Gdview_RecordList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //mod by ming
            if (gdview_RecordList.Columns[e.ColumnIndex].Name == "Curve" && e.RowIndex >= 0)
            {
                long taskId = ProductTaskRecord[e.RowIndex].TaskID;
                string productSN = ProductTaskRecord[e.RowIndex].ProductSN;
                TaskCurve taskCurve = new TaskCurve(taskId, productSN);
                taskCurve.ShowDialog();
            }
        }

        /// <summary>
        /// 登录加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TaskRecord_Load(object sender, EventArgs e)
        {
            InitData();
            bnt_Search_Click(null, null);
        }

        #region 方法
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            ResetData();

            //查询所有可用产品
            ProductTaskRecord = ProductTaskRecordDbHelper.GetAllProductTaskRecords();
            //最新十条产品名称模糊搜索
            ProudctNameData = ProductTaskRecord.OrderByDescending(o => o.ProductTaskRecordID).Select(c => c.ProductName).Distinct().Take(10).ToList();
            this.txt_ProductName.AutoCompleteCustomSource.Clear();
            this.txt_ProductName.AutoCompleteCustomSource.AddRange(ProudctNameData.ToArray());
            this.txt_ProductName.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
            this.txt_ProductName.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
            //最新十条条码模糊搜索
            BarcodeData = ProductTaskRecord.OrderByDescending(o => o.ProductTaskRecordID).Select(c => c.ProductSN).Distinct().Take(10).ToList();
            this.txt_Barcode.AutoCompleteCustomSource.Clear();
            this.txt_Barcode.AutoCompleteCustomSource.AddRange(BarcodeData.ToArray());
            this.txt_Barcode.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
            this.txt_Barcode.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;

            //表格只读，不可修改
            gdview_RecordList.ReadOnly = true;
            //列标题居中
            gdview_RecordList.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            //单元格字体居中显示
            gdview_RecordList.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            //显示行网格线，隐藏列网格线
            this.gdview_RecordList.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal;
            this.gdview_RecordList.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
            this.gdview_RecordList.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
            // 设置选中单元格的背景颜色
            gdview_RecordList.DefaultCellStyle.SelectionBackColor = System.Drawing.ColorTranslator.FromHtml("#BFEFFF");
            //设置选择模式为整行选择
            gdview_RecordList.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //// 设置选中单元格的前景颜色
            //gdview_RecordList.DefaultCellStyle.SelectionForeColor = Color.Black;

            //设置DataGridView支持自动换行
            this.gdview_RecordList.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            //this.gdview_RecordList.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;//确定可见列的自动调整大小模式
            gdview_RecordList.RowTemplate.Height = 35;
            this.gdview_RecordList.DefaultCellStyle.Font = defaultFont;

            // 创建一个新的Font对象
            Font columnFont = new Font("Microsoft YaHei", 12, FontStyle.Bold);
            // 设置列头的默认单元格样式
            gdview_RecordList.ColumnHeadersDefaultCellStyle.Font = columnFont;

            //gdview_RecordList.EnableHeadersVisualStyles = false; // 关闭视觉样式以显示网格线
            //gdview_RecordList.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; // 显示列表头网格线
            //gdview_RecordList.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; // 显示行表头网格线

            columnParams.Clear();
            //添加表格标题
            columnParams.Add("序号", true);
            columnParams.Add("产品名称", true);
            columnParams.Add("条码", true);
            columnParams.Add("任务参数", true);
            columnParams.Add("作业时间", true);
            columnParams.Add("任务状态", true);
            columnParams.Add("扭力", false);
            columnParams.Add("电批位置", true);
            columnParams.Add("任务图片", false);
            columnParams.Add("任务顺序", true);
            columnParams.Add("套筒型号", true);
            columnParams.Add("螺丝型号", true);
            columnParams.Add("NG处理结果", true);
            columnParams.Add("备注", false);
            columnParams.Add("操作", true);//mod by ming 

            columnHeaderText.Clear();
            columnHeaderText.Add("Num", "序号");
            columnHeaderText.Add("ProductName", "产品名称");
            columnHeaderText.Add("ProductSN", "条码");
            columnHeaderText.Add("ScrewDriverParam", "任务参数");
            columnHeaderText.Add("WorkTime", "作业时间");
            columnHeaderText.Add("State", "任务状态");
            columnHeaderText.Add("TaskPama1", "扭力");
            columnHeaderText.Add("ScrewLocaiton", "电批位置");
            columnHeaderText.Add("TaskImgNo", "任务图片");
            columnHeaderText.Add("WorkNo", "任务顺序");
            columnHeaderText.Add("SleeveModel", "套筒型号");
            columnHeaderText.Add("ScrewModel", "螺丝型号");
            columnHeaderText.Add("NGType", "NG处理结果");
            columnHeaderText.Add("NGReMark", "备注");

            gdview_RecordList.Columns.Clear();
            foreach (var columnItem in columnHeaderText)
            {
                gdview_RecordList.Columns.Add(columnItem.Key, columnItem.Value);
            }

            //mod by ming 2024-11-25
            DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn
            {
                Name = "Curve",
                HeaderText = "操作",
                Text = "查看"
            };
            dataGridViewButtonColumn.DefaultCellStyle.NullValue = "查看";
            gdview_RecordList.Columns.Add(dataGridViewButtonColumn);



            gdview_RecordList.Columns["Num"].Width = 80;
            gdview_RecordList.Columns["ProductName"].Width = 100;
            gdview_RecordList.Columns["ProductSN"].Width = 100;
            gdview_RecordList.Columns["ScrewDriverParam"].Width = 80;
            gdview_RecordList.Columns["WorkTime"].Width = 120;
            gdview_RecordList.Columns["State"].Width = 80;
            gdview_RecordList.Columns["TaskPama1"].Width = 100;
            gdview_RecordList.Columns["ScrewLocaiton"].Width = 120;
            gdview_RecordList.Columns["TaskImgNo"].Width = 60;
            gdview_RecordList.Columns["WorkNo"].Width = 80;
            gdview_RecordList.Columns["SleeveModel"].Width = 80;
            gdview_RecordList.Columns["ScrewModel"].Width = 80;
            gdview_RecordList.Columns["NGType"].Width = 100;
            gdview_RecordList.Columns["NGReMark"].Width = 150;
            gdview_RecordList.Columns["Curve"].Width = 60;


            int n = 0;
            foreach (var columnItem in columnParams)
            {
                if (columnItem.Value)
                {
                    gdview_RecordList.Columns[n].Visible = true;
                }
                else
                {
                    gdview_RecordList.Columns[n].Visible = false;
                }
                n++;
            }
            settingColumnCombox.InitData(columnParams);

            screwModels = Bll.GetAllScrewModels();
            cbx_ScrewModel.DataSource = screwModels;
            cbx_ScrewModel.DisplayMember = "Model";
            cbx_ScrewModel.Text = null;

            //screwdriverParams = Bll.GetAllParameters();
            //cbx_TaskParam.DataSource = screwdriverParams;
            //cbx_TaskParam.DisplayMember = "Content";
            //cbx_TaskParam.Text = null;

            //mod by zhu
            screwdriverParams = Bll.GetAllDDKParameter();
            cbx_TaskParam.DisplayMember = "name";
            cbx_TaskParam.ValueMember = "TaskID";
            cbx_TaskParam.DataSource = screwdriverParams;
            cbx_TaskParam.Text = null;

            List<string> stateScources = new List<string>();
            foreach (string status in TaskStatus.Values)
            {
                stateScources.Add(status);
            }
            cbx_TaskStatus.DataSource = stateScources;
            cbx_TaskStatus.Text = null;

            sleeveModels = Bll.GetAllSleeveModels();
            //gdview_RecordList.Columns[gdview_RecordList.ColumnCount - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }


        /// <summary>
        /// 重置数据
        /// </summary>
        public void ResetData()
        {
            ResetProductAndBarcode();
            historyRecordButton.ResetStatus();
            ChangeHistoryRecord(HistoryRecordType.Today);

            lbl_ProductSum.Text = null;
            lbl_TaskSum.Text = null;
            lbl_NGSum.Text = null;
            lbl_PassNum.Text = null;

            gdview_RecordList.Rows.Clear();
            cbx_ScrewModel.Text = null;
            cbx_TaskParam.Text = null;
            cbx_TaskStatus.Text = null;
        }

        /// <summary>
        /// 重置产品名称和条码
        /// </summary>
        public void ResetProductAndBarcode()
        {
            txt_ProductName.Text = null;
            txt_Barcode.Text = null;
            hasProductName = false;
            hasBarcode = false;
            txt_ProductName_Leave(null, null);
            txt_Barcode_Leave(null, null);
        }

        /// <summary>
        /// 修改搜索日期
        /// </summary>
        /// <param name="historyRecordType"></param>
        private void ChangeHistoryRecord(HistoryRecordType historyRecordType)
        {
            if (historyRecordType == HistoryRecordType.Today)
            {
                dt_WorkStartTime.Value = DateTime.Now;
                dt_WorkEndTime.Value = DateTime.Now;
            }
            else if (historyRecordType == HistoryRecordType.Yesterday)
            {
                dt_WorkStartTime.Value = DateTime.Now.AddDays(-1);
                dt_WorkEndTime.Value = DateTime.Now.AddDays(-1);
            }
            else if (historyRecordType == HistoryRecordType.Last30Day)
            {
                dt_WorkStartTime.Value = DateTime.Now.AddDays(-30);
                dt_WorkEndTime.Value = DateTime.Now;
            }
            else if (historyRecordType == HistoryRecordType.Last90Day)
            {
                dt_WorkStartTime.Value = DateTime.Now.AddDays(-90);
                dt_WorkEndTime.Value = DateTime.Now;
            }
        }

        /// <summary>
        /// 选中列表标题
        /// </summary>
        private void SelectColumnParamEvent(List<string> columnNames)
        {
            for (int i = 0; i < gdview_RecordList.Columns.Count; i++)
            {
                gdview_RecordList.Columns[i].Visible = columnNames.Exists(c => c == gdview_RecordList.Columns[i].HeaderText);
                //add by ming 2025-11-25
                if (gdview_RecordList.Columns[i].HeaderText == "产品名称")
                {
                    gdview_RecordList.Columns["ProductName"].Width = 120;
                }
                if (gdview_RecordList.Columns[i].HeaderText == "条码")
                {
                    gdview_RecordList.Columns["ProductSN"].Width = 120;
                }
                if (gdview_RecordList.Columns[i].HeaderText == "作业时间")
                {
                    gdview_RecordList.Columns["WorkTime"].Width = 160;
                }
                if (gdview_RecordList.Columns[i].HeaderText == "电批位置")
                {
                    gdview_RecordList.Columns["ScrewLocaiton"].Width = 140;
                }
            }
        }

        #endregion

        #region 产品名文本框提示
        bool hasProductName = false;//判断输入框是否有文本 
        private void txt_ProductName_Enter(object sender, EventArgs e)
        {
            if (hasProductName == false)
                txt_ProductName.Text = "";

            txt_ProductName.ForeColor = Color.Black;
        }

        private void txt_ProductName_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_ProductName.Text))
            {
                txt_ProductName.Text = "请输入";
                txt_ProductName.ForeColor = Color.LightGray;
                hasProductName = false;
            }
            else
                hasProductName = true;
        }
        #endregion

        #region 条码文本框提示
        bool hasBarcode = false;//判断输入框是否有文本 
        private void txt_Barcode_Enter(object sender, EventArgs e)
        {
            if (hasBarcode == false)
                txt_Barcode.Text = "";

            txt_Barcode.ForeColor = Color.Black;
        }

        private void txt_Barcode_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_Barcode.Text))
            {
                txt_Barcode.Text = "请输入";
                txt_Barcode.ForeColor = Color.LightGray;
                hasBarcode = false;
            }
            else
                hasBarcode = true;
        }

        #endregion

        /// <summary>
        /// 查询记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bnt_Search_Click(object sender, EventArgs e)
        {
            string productName = txt_ProductName.Text == "请输入" ? null : txt_ProductName.Text.Trim();
            string barcode = txt_Barcode.Text == "请输入" ? null : txt_Barcode.Text.Trim();
            string taskStatus = cbx_TaskStatus.Text;
            string screwmodel = cbx_ScrewModel.Text;
            string taskparam = cbx_TaskParam.Text;
            DateTime startTime = Convert.ToDateTime(dt_WorkStartTime.Text);
            DateTime endTime = Convert.ToDateTime(dt_WorkEndTime.Text).AddDays(1).AddSeconds(-1);
            HistoryRecordType historyRecordType = historyRecordButton.historyRecordType;

            ProductTaskRecord = ProductTaskRecordDbHelper.GetAllProductTaskRecords();
            List<ProductTaskRecord> productTasks = ProductTaskRecord;

            lbl_ProductSum.Text = null;
            lbl_TaskSum.Text = null;
            lbl_NGSum.Text = null;
            lbl_PassNum.Text = null;
            gdview_RecordList.Rows.Clear();

            if (!string.IsNullOrEmpty(productName))
            {
                productTasks = ProductTaskRecord.FindAll(o => o.ProductName.Contains(productName));
            }

            if (!string.IsNullOrEmpty(barcode))
            {
                productTasks = productTasks.FindAll(o => o.ProductSN.StartsWith(barcode));
            }

            if (!string.IsNullOrEmpty(taskStatus))
            {
                int status = 0;
                foreach (var keyValue in TaskStatus)
                {
                    if (keyValue.Value.Equals(taskStatus))
                    {
                        status = keyValue.Key;
                    }
                }
                if (status >= 0)
                {
                    productTasks = productTasks.FindAll(o => o.State == status);
                }
            }

            if (!string.IsNullOrEmpty(screwmodel))
            {
                var screwModel = screwModels.Find(o => o.Model == screwmodel.Trim());
                if (screwModel != null)
                {
                    productTasks = productTasks.FindAll(o => o.ScrewModel == screwModel.Id);
                }
                else
                {
                    return;
                }
            }
            if (!string.IsNullOrEmpty(taskparam))
            {
                //mod by zhu
                var screwdriverParam = screwdriverParams.Find(o => o.name == taskparam.Trim());
                if (screwdriverParam != null)
                {
                    //mod by zhu
                    productTasks = productTasks.FindAll(o => o.ScrewDriverParam == screwdriverParam.taskId);
                }
                else
                {
                    return;
                }
            }

            productTasks = productTasks.FindAll(o => o.UpdateTime >= startTime && o.UpdateTime <= endTime);
            ProductTaskRecord = productTasks;
            gdview_RecordList.Rows.Clear();
            for (int i = 0; i < productTasks.Count; i++)
            {
                ProductTaskRecord productTask = productTasks[i];
                // 添加一行数据
                gdview_RecordList.Rows.Add();
                // 为这行的各列赋值
                gdview_RecordList.Rows[i].Cells["Num"].Value = i + 1;

                gdview_RecordList.Rows[i].Cells["ProductName"].Value = productTask.ProductName;
                gdview_RecordList.Rows[i].Cells["ProductSN"].Value = productTask.ProductSN;
                var screwdriverParam = screwdriverParams.Find(o => o.taskId == productTask.ScrewDriverParam);
                gdview_RecordList.Rows[i].Cells["ScrewDriverParam"].Value = screwdriverParam?.name;
                gdview_RecordList.Rows[i].Cells["WorkTime"].Value = productTask.UpdateTime;
                TaskStatus.TryGetValue(productTask.State, out string stateValue);
                gdview_RecordList.Rows[i].Cells["State"].Value = stateValue;
                // 0未执行 1 Pass 2 NG 3执行中 4品质PASS 5品质NG 6品质重做
                if (productTask.State == 0)
                {
                    gdview_RecordList.Rows[i].Cells["State"].Style.ForeColor = Color.Gray;
                }
                else if (productTask.State == 1)
                {
                    gdview_RecordList.Rows[i].Cells["State"].Style.ForeColor = Color.Green;
                }
                else if (productTask.State == 2)
                {
                    gdview_RecordList.Rows[i].Cells["State"].Style.ForeColor = Color.Red;
                }
                else if (productTask.State == 3)
                {
                    gdview_RecordList.Rows[i].Cells["State"].Style.ForeColor = Color.Orange;
                }
                else if (productTask.State == 4)
                {
                    gdview_RecordList.Rows[i].Cells["State"].Style.ForeColor = Color.Blue;
                }
                else if (productTask.State == 5)
                {
                    gdview_RecordList.Rows[i].Cells["State"].Style.ForeColor = Color.Violet;
                }
                else if (productTask.State == 6)
                {
                    gdview_RecordList.Rows[i].Cells["State"].Style.ForeColor = Color.Brown;
                }

                gdview_RecordList.Rows[i].Cells["TaskPama1"].Value = productTask.TaskPama1;
                var locReal = !string.IsNullOrWhiteSpace(productTask.ScrewLocationReal) ? $"\r\n执行:{productTask.ScrewLocationReal}" : "";
                gdview_RecordList.Rows[i].Cells["ScrewLocaiton"].Value = $"坐标:{productTask.ScrewLocation}{locReal}";
                gdview_RecordList.Rows[i].Cells["TaskImgNo"].Value = productTask.TaskImgNo;
                gdview_RecordList.Rows[i].Cells["WorkNo"].Value = productTask.WorkNo;
                var sleeveModel = sleeveModels.Find(o => o.Id == productTask.SleeveModel);
                gdview_RecordList.Rows[i].Cells["SleeveModel"].Value = sleeveModel?.Model;
                var screwModel = screwModels.Find(o => o.Id == productTask.ScrewModel);
                gdview_RecordList.Rows[i].Cells["ScrewModel"].Value = screwModel?.Model;
                gdview_RecordList.Rows[i].Cells["NGType"].Value = productTask.NGType;
                gdview_RecordList.Rows[i].Cells["NGReMark"].Value = productTask.NGReMark;

            }


            int recordCount = productTasks.Select(o => o.ProductSN).Distinct().Count();
            int sumTask = productTasks.Count;
            int unFinishNum = productTasks.FindAll(o => o.State == 2).Count;
            float passNum = sumTask == 0 ? 0 : (float)productTasks.FindAll(o => o.State == 1).Count / sumTask;

            lbl_ProductSum.Text = recordCount.ToString();
            lbl_TaskSum.Text = sumTask.ToString();
            lbl_NGSum.Text = unFinishNum.ToString();
            lbl_PassNum.Text = (passNum * 100.0f).ToString("F2") + "%";

        }

        /// <summary>
        /// 重置搜索信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Reset_Click(object sender, EventArgs e)
        {
            ResetData();
            bnt_Search_Click(null, null);
        }

        /// <summary>
        /// 导出数据文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Export_Click(object sender, EventArgs e)
        {
            try
            {
                if (gdview_RecordList.Rows.Count > 0)
                {
                    ExcelHelper.ExportToCSV(gdview_RecordList, false);
                }
                else
                {
                    MessageBox.Show("未查询出数据，无法导出!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"任务测试记录，btn_Export_Click->{ex.Message}");
            }

        }

        /// <summary>
        /// 设置鼠标悬浮行的背景和前景颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gdview_RecordList_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                gdview_RecordList.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.AliceBlue;
            }
        }

        /// <summary>
        /// 鼠标离开时恢复默认颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gdview_RecordList_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                gdview_RecordList.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
            }
        }

        /// <summary>
        /// 选中不改变前景色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Gdview_RecordList_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            e.CellStyle.SelectionForeColor = e.CellStyle.ForeColor;
        }

    }
}
